#!/bin/bash
# Script that checks against build infrastructure mistakes in the examples.

# Copyright (C) 2018 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.


# func_init sample
# sets environment variables for building and running the given sample.
func_init ()
{
  case "$1" in
    hello-objc-gnustep) . /usr/share/GNUstep/Makefiles/GNUstep.sh ;;
  esac
}


# func_autogen sample
# adds generated build infrastructure files to the given sample.
func_autogen ()
{
  case "$1" in
    hello-objc-gnustep)
      (func_init "$1"; cd "$1" && ./autogen.sh)
      ;;
    *)
      (cd "$1" && ./autogen.sh)
      ;;
  esac
}

# func_autoclean sample
# removes generated build infrastructure files from the given sample.
func_autoclean ()
{
  case "$1" in
    hello-objc-gnustep)
      (func_init "$1"; cd "$1" && ./autoclean.sh)
      ;;
    *)
      (cd "$1" && ./autoclean.sh)
      ;;
  esac
}

# func_configure sample [builddir]
# runs configure for the given sample, optionally in a VPATH build.
func_configure ()
{
  case "$1" in
    hello-objc-gnustep) ;;
    *)
      if test -n "$2"; then
        (cd "$1"
         mkdir "$2"
         (cd "$2" && ../configure)
        )
      else
        (cd "$1" && ./configure)
      fi
      ;;
  esac
}

# func_distclean sample [builddir]
# undoes the effects of func_configure sample [builddir].
func_distclean ()
{
  case "$1" in
    hello-objc-gnustep) ;;
    *)
      if test -n "$2"; then
        (cd "$1/$2" && make distclean)
      else
        (cd "$1" && make distclean)
      fi
      ;;
  esac
}

# func_maintainerclean sample [builddir]
# also removes files that are expensive to rebuild.
func_maintainerclean ()
{
  case "$1" in
    hello-objc-gnustep)
      (func_init "$1"; cd "$1" && make distclean)
      ;;
    *)
      if test -n "$2"; then
        (cd "$1/$2" && make maintainer-clean)
      else
        (cd "$1" && make maintainer-clean)
      fi
      ;;
  esac
}


# func_check_autoclean sample
# checks whether the autoclean.sh script is complete.
func_check_autoclean ()
{
  sample="$1"
  rm -rf "$sample.bak"
  cp -a "$sample" "$sample.bak"
  func_autogen "$sample"
  func_autoclean "$sample"
  LC_ALL=C diff -r -q "$sample.bak" "$sample" | sed -n -e 's/^Only in //p' | sed -e 's|: |/|' > "$sample.out"
  if ! test -s "$sample.out"; then
    rm -f "$sample.out"
  fi
  rm -rf "$sample.bak"
}

func_check_autoclean_all ()
{
  rm -f hello-*.out
  func_check_autoclean hello-c
  func_check_autoclean hello-c-gnome
  func_check_autoclean hello-c-gnome3
  func_check_autoclean hello-c++
  func_check_autoclean hello-c++-qt
  func_check_autoclean hello-c++-kde
  func_check_autoclean hello-c++-gnome
  func_check_autoclean hello-c++-wxwidgets
  func_check_autoclean hello-objc
  func_check_autoclean hello-objc-gnustep
  func_check_autoclean hello-objc-gnome
  func_check_autoclean hello-sh
  func_check_autoclean hello-python
  func_check_autoclean hello-clisp
  func_check_autoclean hello-librep
  func_check_autoclean hello-guile
  func_check_autoclean hello-smalltalk
  func_check_autoclean hello-java
  func_check_autoclean hello-java-awt
  func_check_autoclean hello-java-swing
  func_check_autoclean hello-java-qtjambi
  func_check_autoclean hello-csharp
  func_check_autoclean hello-csharp-forms
  func_check_autoclean hello-gawk
  func_check_autoclean hello-pascal
  func_check_autoclean hello-ycp
  func_check_autoclean hello-tcl
  func_check_autoclean hello-tcl-tk
  func_check_autoclean hello-perl
  func_check_autoclean hello-php
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_autoclean error: Leftover files:"
    cat hello-*.out
    rm -f hello-*.out
    exit 1
  fi
}


# Known configure failures:
# hello-c-gnome: error: Could not find the gnomeConf.sh file that is generated by gnome-libs install
# hello-c-gnome3: error: can't find gtk+-3.0 >= 3.10
# hello-c++-qt: error: cannot find correct Qt headers!
# hello-c++-kde: configure: error: Qt (>= Qt 3.1.0) (headers and libraries) not found. Please check your installation!
# hello-c++-gnome: error: Could not find the gnomeConf.sh file that is generated by gnome-libs install
# hello-objc-gnome: error: Could not find the gnomeConf.sh file that is generated by gnome-libs install
# hello-ycp: *** Essential program y2base not found

# func_check_distclean sample
# checks 'make distclean' directly after 'configure'.
func_check_distclean ()
{
  sample="$1"
  rm -rf "$sample.bak"
  func_autogen "$sample"
  cp -a "$sample" "$sample.bak"
  if func_configure "$sample" > "$sample.log" 2>&1; then
    rm -f "$sample.log"
    func_distclean "$sample"
    LC_ALL=C diff -r -q "$sample.bak" "$sample" | sed -n -e 's/^Only in //p' | sed -e 's|: |/|' > "$sample.out"
  fi
  func_autoclean "$sample"
  if ! test -s "$sample.out"; then
    rm -f "$sample.out"
  fi
  rm -rf "$sample.bak"
}

func_check_distclean_all ()
{
  rm -f hello-*.log hello-*.out
  func_check_distclean hello-c
 #func_check_distclean hello-c-gnome
 #func_check_distclean hello-c-gnome3
  func_check_distclean hello-c++
 #func_check_distclean hello-c++-qt
 #func_check_distclean hello-c++-kde
 #func_check_distclean hello-c++-gnome
  func_check_distclean hello-c++-wxwidgets
  func_check_distclean hello-objc
  func_check_distclean hello-objc-gnustep
 #func_check_distclean hello-objc-gnome
  func_check_distclean hello-sh
  func_check_distclean hello-python
  func_check_distclean hello-clisp
  func_check_distclean hello-librep
  func_check_distclean hello-guile
  func_check_distclean hello-smalltalk
  func_check_distclean hello-java
  func_check_distclean hello-java-awt
  func_check_distclean hello-java-swing
  func_check_distclean hello-java-qtjambi
  func_check_distclean hello-csharp
  func_check_distclean hello-csharp-forms
  func_check_distclean hello-gawk
  func_check_distclean hello-pascal
 #func_check_distclean hello-ycp
  func_check_distclean hello-tcl
  func_check_distclean hello-tcl-tk
  func_check_distclean hello-perl
  func_check_distclean hello-php
  if (shopt -s failglob; echo hello-*.log) >/dev/null 2>/dev/null; then
    echo "*** func_check_distclean error: 'configure' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_distclean error: incomplete 'make distclean'"
    echo hello-*.out
    exit 1
  fi
}


# Known make failures:
# hello-java-qtjambi: error: package com.trolltech.qt.core does not exist

# func_check_maintainerclean sample
# checks 'make distclean' after 'configure; make'.
func_check_maintainerclean ()
{
  sample="$1"
  rm -rf "$sample.bak"
  func_autogen "$sample"
  cp -a "$sample" "$sample.bak"
  if func_configure "$sample"; then
    if (func_init "$sample"; cd "$sample" && make) > "$sample.log" 2>&1; then
      rm -f "$sample.log"
    fi
  fi
  func_maintainerclean "$sample"
  # TODO: Remove .pot files workaround after next release.
  # TODO: Remove .po~ files workaround.
  LC_ALL=C diff -r -q "$sample.bak" "$sample" | sed -n -e 's/^Only in //p' | sed -e 's|: |/|' | grep "^${sample}/" | { if test -f "$sample"/po/Makevars || test "$sample" = hello-objc-gnustep; then grep -v '\.pot$'; else cat; fi; } | grep -v '\.po~$' > "$sample.out"
  func_autoclean "$sample"
  if ! test -s "$sample.out"; then
    rm -f "$sample.out"
  fi
  rm -rf "$sample.bak"
}

func_check_maintainerclean_all ()
{
  rm -f hello-*.log hello-*.out
  func_check_maintainerclean hello-c
 #func_check_maintainerclean hello-c-gnome
 #func_check_maintainerclean hello-c-gnome3
  func_check_maintainerclean hello-c++
 #func_check_maintainerclean hello-c++-qt
 #func_check_maintainerclean hello-c++-kde
 #func_check_maintainerclean hello-c++-gnome
  func_check_maintainerclean hello-c++-wxwidgets
  func_check_maintainerclean hello-objc
  func_check_maintainerclean hello-objc-gnustep
 #func_check_maintainerclean hello-objc-gnome
  func_check_maintainerclean hello-sh
  func_check_maintainerclean hello-python
  func_check_maintainerclean hello-clisp
  func_check_maintainerclean hello-librep
  func_check_maintainerclean hello-guile
  func_check_maintainerclean hello-smalltalk
  func_check_maintainerclean hello-java
  func_check_maintainerclean hello-java-awt
  func_check_maintainerclean hello-java-swing
 #func_check_maintainerclean hello-java-qtjambi
  func_check_maintainerclean hello-csharp
  func_check_maintainerclean hello-csharp-forms
  func_check_maintainerclean hello-gawk
  func_check_maintainerclean hello-pascal
 #func_check_maintainerclean hello-ycp
  func_check_maintainerclean hello-tcl
  func_check_maintainerclean hello-tcl-tk
  func_check_maintainerclean hello-perl
  func_check_maintainerclean hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_maintainerclean error: 'make' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_maintainerclean error: incomplete 'make maintainer-clean'"
    echo hello-*.out
    exit 1
  fi
}


# func_check_maintainerclean_vpath sample
# checks 'make distclean' after 'configure; make' with a VPATH build.
func_check_maintainerclean_vpath ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep) ;;
    *)
      rm -rf "$sample.bak"
      func_autogen "$sample"
      cp -a "$sample" "$sample.bak"
      if func_configure "$sample" build; then
        if (func_init "$sample"; cd "$sample"/build && make) > "$sample.log" 2>&1; then
          rm -f "$sample.log"
        fi
      fi
      func_maintainerclean "$sample" build
      # TODO: Remove .pot files workaround after next release.
      # TODO: Remove .po~ files workaround.
      find "$sample"/build -type f | LC_ALL=C sort | { if test -f "$sample"/po/Makevars; then grep -v '\.pot$'; else cat; fi; } | grep -v '\.po~$' > "$sample.out"
      rm -rf "$sample"/build
      func_autoclean "$sample"
      if ! test -s "$sample.out"; then
        rm -f "$sample.out"
      fi
      rm -rf "$sample.bak"
      ;;
  esac
}

func_check_maintainerclean_vpath_all ()
{
  rm -f hello-*.log hello-*.out
  func_check_maintainerclean_vpath hello-c
 #func_check_maintainerclean_vpath hello-c-gnome
 #func_check_maintainerclean_vpath hello-c-gnome3
  func_check_maintainerclean_vpath hello-c++
 #func_check_maintainerclean_vpath hello-c++-qt
 #func_check_maintainerclean_vpath hello-c++-kde
 #func_check_maintainerclean_vpath hello-c++-gnome
  func_check_maintainerclean_vpath hello-c++-wxwidgets
  func_check_maintainerclean_vpath hello-objc
  func_check_maintainerclean_vpath hello-objc-gnustep
 #func_check_maintainerclean_vpath hello-objc-gnome
  func_check_maintainerclean_vpath hello-sh
  func_check_maintainerclean_vpath hello-python
  func_check_maintainerclean_vpath hello-clisp
  func_check_maintainerclean_vpath hello-librep
  func_check_maintainerclean_vpath hello-guile
  func_check_maintainerclean_vpath hello-smalltalk
  func_check_maintainerclean_vpath hello-java
  func_check_maintainerclean_vpath hello-java-awt
  func_check_maintainerclean_vpath hello-java-swing
 #func_check_maintainerclean_vpath hello-java-qtjambi
  func_check_maintainerclean_vpath hello-csharp
  func_check_maintainerclean_vpath hello-csharp-forms
  func_check_maintainerclean_vpath hello-gawk
  func_check_maintainerclean_vpath hello-pascal
 #func_check_maintainerclean_vpath hello-ycp
  func_check_maintainerclean_vpath hello-tcl
  func_check_maintainerclean_vpath hello-tcl-tk
  func_check_maintainerclean_vpath hello-perl
  func_check_maintainerclean_vpath hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_maintainerclean_vpath error: 'make' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_maintainerclean_vpath error: incomplete 'make maintainer-clean'"
    echo hello-*.out
    exit 1
  fi
}


# func_check_dist sample
# checks 'make dist' after 'configure; make'.
func_check_dist ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep) ;;
    *)
      func_autogen "$sample"
      if func_configure "$sample"; then
        if (func_init "$sample"; cd "$sample" && make); then
          if (func_init "$sample"; cd "$sample" && make dist) > "$sample.log" 2>&1; then
            rm -f "$sample.log"
            (func_init "$sample"; cd "$sample" && make distclean)
            rm -f `find "$sample" -name '*~'` `find "$sample" -name '*.orig'`
            rm -rf "$sample/autom4te.cache"
            if test -f "$sample/$sample-0.tar.gz"; then
              (cd "$sample" && tar xfz "$sample-0.tar.gz")
              LC_ALL=C diff -r -q "$sample" "$sample/$sample-0" | grep -v "^Only in $sample: $sample-0$" | grep -v "^Only in $sample: $sample-0.tar.gz$" | grep -v "^Only in $sample: BUGS$" > "$sample.out"
            else
              echo "$sample-0.tar.gz was not created" > "$sample.out"
            fi
          fi
          rm -rf "$sample/$sample-0"
          rm -f "$sample/$sample-0.tar.gz"
        fi
      fi
      func_configure "$sample"
      func_maintainerclean "$sample"
      func_autoclean "$sample"
      if ! test -s "$sample.out"; then
        rm -f "$sample.out"
      fi
      ;;
  esac
}

func_check_dist_all ()
{
  rm -f hello-*.log hello-*.out
  func_check_dist hello-c
 #func_check_dist hello-c-gnome
 #func_check_dist hello-c-gnome3
  func_check_dist hello-c++
 #func_check_dist hello-c++-qt
 #func_check_dist hello-c++-kde
 #func_check_dist hello-c++-gnome
  func_check_dist hello-c++-wxwidgets
  func_check_dist hello-objc
  func_check_dist hello-objc-gnustep
 #func_check_dist hello-objc-gnome
  func_check_dist hello-sh
  func_check_dist hello-python
  func_check_dist hello-clisp
  func_check_dist hello-librep
  func_check_dist hello-guile
  func_check_dist hello-smalltalk
  func_check_dist hello-java
  func_check_dist hello-java-awt
  func_check_dist hello-java-swing
 #func_check_dist hello-java-qtjambi
  func_check_dist hello-csharp
  func_check_dist hello-csharp-forms
  func_check_dist hello-gawk
  func_check_dist hello-pascal
 #func_check_dist hello-ycp
  func_check_dist hello-tcl
  func_check_dist hello-tcl-tk
  func_check_dist hello-perl
  func_check_dist hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_dist error: 'make dist' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_dist error: tarball created by 'make dist' does not contain the expected files"
    echo hello-*.out
    exit 1
  fi
}


# func_check_dist_vpath sample
# checks 'make dist' after 'configure; make' with a VPATH build
func_check_dist_vpath ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep) ;;
    *)
      func_autogen "$sample"
      if func_configure "$sample" build; then
        if (func_init "$sample"; cd "$sample"/build && make); then
          if (func_init "$sample"; cd "$sample"/build && make dist) > "$sample.log" 2>&1; then
            rm -f "$sample.log"
            (func_init "$sample"; cd "$sample"/build && make distclean)
            rm -f `find "$sample" -name '*~'` `find "$sample" -name '*.orig'`
            rm -rf "$sample/autom4te.cache"
            if test -f "$sample/build/$sample-0.tar.gz"; then
              (cd "$sample"/build && tar xfz "$sample-0.tar.gz")
              # TODO: Remove stamp-po workaround after next release.
              LC_ALL=C diff -r -q "$sample" "$sample/build/$sample-0" | grep -v "^Only in $sample: build$" | grep -v "^Only in $sample: BUGS$" | { if test -f "$sample"/po/Makevars; then grep -v "^Only in $sample/build/$sample-0/po: stamp-po$"; else cat; fi; } > "$sample.out"
            else
              echo "$sample-0.tar.gz was not created" > "$sample.out"
            fi
          fi
          rm -rf "$sample/build/$sample-0"
          rm -f "$sample/build/$sample-0.tar.gz"
        fi
      fi
      rm -rf "$sample"/build
      func_autoclean "$sample"
      if ! test -s "$sample.out"; then
        rm -f "$sample.out"
      fi
      ;;
  esac
}

func_check_dist_vpath_all ()
{
  rm -f hello-*.log hello-*.out
  func_check_dist_vpath hello-c
 #func_check_dist_vpath hello-c-gnome
 #func_check_dist_vpath hello-c-gnome3
  func_check_dist_vpath hello-c++
 #func_check_dist_vpath hello-c++-qt
 #func_check_dist_vpath hello-c++-kde
 #func_check_dist_vpath hello-c++-gnome
  func_check_dist_vpath hello-c++-wxwidgets
  func_check_dist_vpath hello-objc
  func_check_dist_vpath hello-objc-gnustep
 #func_check_dist_vpath hello-objc-gnome
  func_check_dist_vpath hello-sh
  func_check_dist_vpath hello-python
  func_check_dist_vpath hello-clisp
  func_check_dist_vpath hello-librep
  func_check_dist_vpath hello-guile
  func_check_dist_vpath hello-smalltalk
  func_check_dist_vpath hello-java
  func_check_dist_vpath hello-java-awt
  func_check_dist_vpath hello-java-swing
 #func_check_dist_vpath hello-java-qtjambi
  func_check_dist_vpath hello-csharp
  func_check_dist_vpath hello-csharp-forms
  func_check_dist_vpath hello-gawk
  func_check_dist_vpath hello-pascal
 #func_check_dist_vpath hello-ycp
  func_check_dist_vpath hello-tcl
  func_check_dist_vpath hello-tcl-tk
  func_check_dist_vpath hello-perl
  func_check_dist_vpath hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_dist_vpath error: 'make dist' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_dist_vpath error: tarball created by 'make dist' does not contain the expected files"
    echo hello-*.out
    exit 1
  fi
}


# Base installation directory for all samples.
instdir=/tmp/gtexinst

# func_check_install sample
# checks 'make install' after 'configure; make'.
# You need to check afterwards whether the installed binaries work.
func_check_install ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep)
      # In this sample, you have to check the uninstalled binaries (see the INSTALL file).
      ;;
    *)
      func_autogen "$sample"
      if (cd "$sample" && ./configure --prefix="$instdir/$sample"); then
        if (func_init "$sample"; cd "$sample" && make); then
          if (func_init "$sample"; cd "$sample" && make install) > "$sample.log" 2>&1; then
            rm -f "$sample.log"
          fi
        fi
      fi
      func_maintainerclean "$sample"
      func_autoclean "$sample"
      ;;
  esac
}

func_check_install_all ()
{
  rm -f hello-*.log
  rm -rf "$instdir/hello-*"
  func_check_install hello-c
 #func_check_install hello-c-gnome
 #func_check_install hello-c-gnome3
  func_check_install hello-c++
 #func_check_install hello-c++-qt
 #func_check_install hello-c++-kde
 #func_check_install hello-c++-gnome
  func_check_install hello-c++-wxwidgets
  func_check_install hello-objc
  func_check_install hello-objc-gnustep
 #func_check_install hello-objc-gnome
  func_check_install hello-sh
  func_check_install hello-python
  func_check_install hello-clisp
  func_check_install hello-librep
  func_check_install hello-guile
  func_check_install hello-smalltalk
  func_check_install hello-java
  func_check_install hello-java-awt
  func_check_install hello-java-swing
 #func_check_install hello-java-qtjambi
  func_check_install hello-csharp
  func_check_install hello-csharp-forms
  func_check_install hello-gawk
  func_check_install hello-pascal
 #func_check_install hello-ycp
  func_check_install hello-tcl
  func_check_install hello-tcl-tk
  func_check_install hello-perl
  func_check_install hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_install error: 'make install' failures"
    echo hello-*.log
    exit 1
  fi
}


# func_check_uninstall sample
# checks 'make uninstall' after 'configure; make; make install'.
func_check_uninstall ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep)
      # In this sample, you have to check the uninstalled binaries (see the INSTALL file).
      ;;
    *)
      func_autogen "$sample"
      if (cd "$sample" && ./configure --prefix="$instdir/$sample"); then
        if (func_init "$sample"; cd "$sample" && make); then
          if (func_init "$sample"; cd "$sample" && make install); then
            if (func_init "$sample"; cd "$sample" && make uninstall) > "$sample.log" 2>&1; then
              rm -f "$sample.log"
              (cd "$instdir" && find "$sample" -type f | LC_ALL=C sort) > "$sample.out"
            fi
          fi
        fi
      fi
      func_maintainerclean "$sample"
      func_autoclean "$sample"
      if ! test -s "$sample.out"; then
        rm -f "$sample.out"
      fi
      ;;
  esac
}

func_check_uninstall_all ()
{
  rm -f hello-*.log hello-*.out
  rm -rf "$instdir/hello-*"
  func_check_uninstall hello-c
 #func_check_uninstall hello-c-gnome
 #func_check_uninstall hello-c-gnome3
  func_check_uninstall hello-c++
 #func_check_uninstall hello-c++-qt
 #func_check_uninstall hello-c++-kde
 #func_check_uninstall hello-c++-gnome
  func_check_uninstall hello-c++-wxwidgets
  func_check_uninstall hello-objc
  func_check_uninstall hello-objc-gnustep
 #func_check_uninstall hello-objc-gnome
  func_check_uninstall hello-sh
  func_check_uninstall hello-python
  func_check_uninstall hello-clisp
  func_check_uninstall hello-librep
  func_check_uninstall hello-guile
  func_check_uninstall hello-smalltalk
  func_check_uninstall hello-java
  func_check_uninstall hello-java-awt
  func_check_uninstall hello-java-swing
 #func_check_uninstall hello-java-qtjambi
  func_check_uninstall hello-csharp
  func_check_uninstall hello-csharp-forms
  func_check_uninstall hello-gawk
  func_check_uninstall hello-pascal
 #func_check_uninstall hello-ycp
  func_check_uninstall hello-tcl
  func_check_uninstall hello-tcl-tk
  func_check_uninstall hello-perl
  func_check_uninstall hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_uninstall error: 'make uninstall' failures"
    echo hello-*.log
    exit 1
  fi
  if (shopt -s failglob; echo hello-*.out) >/dev/null 2>/dev/null; then
    echo "*** func_check_uninstall error: left-over files"
    echo hello-*.out
    exit 1
  fi
}


# func_check_distcheck sample
# checks 'make distcheck' after 'configure; make'.
func_check_distcheck ()
{
  sample="$1"
  case "$sample" in
    hello-objc-gnustep) ;;
    *)
      func_autogen "$sample"
      if func_configure "$sample"; then
        if (func_init "$sample"; cd "$sample" && make); then
          if (func_init "$sample"; cd "$sample" && make distcheck) > "$sample.log" 2>&1; then
            rm -f "$sample.log"
          fi
          if test -d "$sample/$sample-0"; then chmod -R u+w "$sample/$sample-0"; fi
          rm -rf "$sample/$sample-0"
          rm -f "$sample/$sample-0.tar.gz"
        fi
      fi
      func_maintainerclean "$sample"
      func_autoclean "$sample"
      if ! test -s "$sample.out"; then
        rm -f "$sample.out"
      fi
      ;;
  esac
}

func_check_distcheck_all ()
{
  rm -f hello-*.log
  func_check_distcheck hello-c
 #func_check_distcheck hello-c-gnome
 #func_check_distcheck hello-c-gnome3
  func_check_distcheck hello-c++
 #func_check_distcheck hello-c++-qt
 #func_check_distcheck hello-c++-kde
 #func_check_distcheck hello-c++-gnome
  func_check_distcheck hello-c++-wxwidgets
  func_check_distcheck hello-objc
  func_check_distcheck hello-objc-gnustep
 #func_check_distcheck hello-objc-gnome
  func_check_distcheck hello-sh
  func_check_distcheck hello-python
  func_check_distcheck hello-clisp
  func_check_distcheck hello-librep
  func_check_distcheck hello-guile
  func_check_distcheck hello-smalltalk
  func_check_distcheck hello-java
  func_check_distcheck hello-java-awt
  func_check_distcheck hello-java-swing
 #func_check_distcheck hello-java-qtjambi
  func_check_distcheck hello-csharp
  func_check_distcheck hello-csharp-forms
  func_check_distcheck hello-gawk
  func_check_distcheck hello-pascal
 #func_check_distcheck hello-ycp
  func_check_distcheck hello-tcl
  func_check_distcheck hello-tcl-tk
  func_check_distcheck hello-perl
  func_check_distcheck hello-php
  if (shopt -s failglob; echo hello-*log) >/dev/null 2>/dev/null; then
    echo "*** func_check_distcheck error: 'make distcheck' failures"
    echo hello-*.log
    exit 1
  fi
}


# If you want to extend this script:

# A dummy check function.
func_check ()
{
  :
}

# Complete list of samples.
func_check_all ()
{
  func_check hello-c
  func_check hello-c-gnome
  func_check hello-c-gnome3
  func_check hello-c++
  func_check hello-c++-qt
  func_check hello-c++-kde
  func_check hello-c++-gnome
  func_check hello-c++-wxwidgets
  func_check hello-objc
  func_check hello-objc-gnustep
  func_check hello-objc-gnome
  func_check hello-sh
  func_check hello-python
  func_check hello-clisp
  func_check hello-librep
  func_check hello-guile
  func_check hello-smalltalk
  func_check hello-java
  func_check hello-java-awt
  func_check hello-java-swing
  func_check hello-java-qtjambi
  func_check hello-csharp
  func_check hello-csharp-forms
  func_check hello-gawk
  func_check hello-pascal
  func_check hello-ycp
  func_check hello-tcl
  func_check hello-tcl-tk
  func_check hello-perl
  func_check hello-php
}


# Top-level code.

func_check_autoclean_all
func_check_distclean_all
func_check_maintainerclean_all
func_check_maintainerclean_vpath_all
func_check_dist_all
func_check_dist_vpath_all
func_check_install_all
func_check_uninstall_all
func_check_distcheck_all
